<template>
  <div class="body">
    <table-msg ref="tableMsg"
               :insert-button="true"
               insert-button-text="添加类别"
               :columns="columns"
               :request_value="request_value"
               @insert="insertClassification"
               @update="updateClassification"
               @info="infoClassification"
               @delete="deleteClassification"
               @Reset="resetClassification"
    />
    <classification-insert-form ref="insertForm"/>
    <classification-modify-form ref="modifyForm"/>
    <classification-detail ref="detail"/>
  </div>
</template>

<script>
import TableMsg from '@/components/table/TableMsg'
import { classificationAllList, classificationDelete, classificationReset } from '@/api/classification'
import { ref } from 'vue'
import ClassificationInsertForm from '@/views/administrator/classification/form/classification-insert-form'
import ClassificationModifyForm from '@/views/administrator/classification/form/classification-modify-form'
import ClassificationDetail from '@/views/administrator/classification/detail/classification-detail'
export default {
  name: 'classification-management',
  components: { ClassificationDetail, ClassificationModifyForm, ClassificationInsertForm, TableMsg },
  setup () {
    const columns = [
      { prop: 'name', label: '专栏' },
      { prop: 'summarize', label: '综述' },
      { prop: 'totalArticle', label: '文章总数' },
      { prop: 'viewsNo', label: '浏览数' },
      { prop: 'status', label: '状态', type: 'status', status: ['ENABLE', 'DELETED'], tag: [0, 2] },
      { prop: 'option', label: '操作', type: 'option', width: 340, option: { info: true, update: true, delete: true, reset: true } }
    ]
    return {
      columns,
      request_value: ref({ })
    }
  },
  methods: {
    getClassificationAllList (val) {
      let page = this.$refs.tableMsg.getPage
      if (val) {
        page = val
      }
      classificationAllList(page).then(value => {
        console.log('classification', value)
        this.request_value = value
      })
    },
    insertClassification () {
      this.$refs.insertForm.dialogVisible = true
      this.$refs.insertForm.data = {}
    },
    updateClassification (val) {
      console.log(val)
      this.$refs.modifyForm.dialogVisible = true
      this.$refs.modifyForm.data = val
    },
    infoClassification (val) {
      this.$refs.detail.dialogVisible = true
      this.$refs.detail.data = val
      console.log(val)
    },
    deleteClassification (val) {
      classificationDelete(val).then(value => {
        this.getClassificationAllList()
      })
    },
    resetClassification (val) {
      classificationReset(val).then(value => {
        this.getClassificationAllList()
      })
    }
  },
  mounted () {
    this.getClassificationAllList()
  }
}
</script>

<style scoped>

</style>
